package com.mc.api.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.mc.api.constant.Constants;
import com.mc.api.domain.CustomError;
import com.mc.api.domain.User;
import com.mc.api.service.UserService;
import com.mc.api.utils.TokenUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;

/**
 * @ Program       :  com.ljnt.jwt_login.controller.Login
 * @ Description   :  login控制类
 * @ Author        :  hfy
 * @ CreateDate    :  2021-3-1 14:32
 */
@RestController
    @RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("/isUpdatePWD")
    public Object getUserUpdatePWD(HttpServletRequest request) throws JsonProcessingException{
        User user = TokenUtil.getLoginUser(request);
        String isUpdatePWD = userService.selectUserUpdatePWD(user.getUserName());
        HashMap<String,Object> hs=new HashMap<>();
        hs.put("updatePWDSign",isUpdatePWD);
        return JSONArray.toJSON(hs);
    }

    @GetMapping("/getUser/{taskId}")
    @ResponseBody
    public Object getLastSynUser(@PathVariable String taskId,HttpServletRequest request){
        if(Constants.DEFAULT_TASK_ID.equals(taskId)){
            User user = TokenUtil.getLoginUser(request);
            return JSONArray.toJSON(userService.selectUserByUser(user.getUserName()));
        }
        return JSONArray.toJSON(userService.selectUserByCreateDate(taskId));


    }

    @GetMapping("/expert")
    @ResponseBody
    public Object getLabExpert(){

        CustomError error = new CustomError();
        return JSONArray.toJSON(userService.selectLabExpertDate());
    }
}